package org.fuxia.im.common;

import java.util.HashMap;
import java.util.Map;

/**
 * 通用list数据模型
 *
 */
public class CommonListCellData {

	private static final String ICON = "icon";
	private Map<String,Object> properties ;
	private String displayField ;
	
	public CommonListCellData(String displayField){
		this.displayField = displayField ;
		properties = new HashMap<String, Object>();
	}
	
	public CommonListCellData(Object[][] props,String displayField) {
		this(displayField);
		for(Object[] obj:props){
			if(obj.length!=2){
				throw new RuntimeException("属性长度不对,必须是一个属性名和值的数组");
			}
			properties.put(obj[0].toString(), obj[1]) ;
		}
	}
	
	public CommonListCellData(Map<String,Object> propers,String displayField){
		this(displayField) ;
		this.properties.putAll(propers);
	}
	
	public Object getDisplayValue(){
		return properties.get(displayField) ;
	}
	
	public Object getProperties(String propsName){
		return properties.get(propsName);
	}
	
	public String getIconPath(){
		Object path = properties.get(ICON) ;
		return path == null?null:path.toString() ;
	}
	
	
}
